﻿
//添加原告&被告表格
function addyg(tag) {
    var tbl = null;
    switch (tag) {
        case 1:
            tbl = document.getElementById("tblygzyr");
            break;
        case 2:
            tbl = document.getElementById("tblygfr");
            break;
        case 3:
            tbl = document.getElementById("tblygother");
            break;
        case 5:
            tbl = document.getElementById("tblbgzyr");
            break;
        case 6:
            tbl = document.getElementById("tblbgfr");
            break;
        case 7:
            tbl = document.getElementById("tblbgother");
            break;
        default:
            break;
    }

    var newtbl = tbl.cloneNode(true);
    newtbl.id = newtbl.id +"_"+tag.toString();
    var el = null;
    if (tag < 5) {
        el = document.getElementById("liyg");
    } else {
        el = document.getElementById("libg");
    }
    el.appendChild(newtbl);
}

//删除添加的表格
function deltbl(el) {
    if (confirm("您确定要删除吗？")) {
        var eTbl = el.parentNode.parentNode.parentNode.parentNode;
        eTbl.removeNode(true);
    }
}


function ResPostData() {
    //原告/上诉人
    var liyg = document.getElementById("liyg");

    var atbes = liyg.getElementsByTagName("table");

    //原告信息
    var yglist = "";
    for (var t = 0; t < atbes.length; t++) {
        var otbl = atbes[t];

        var entity = "0"; //当事人类型（0：原告；1：被告）
        var id = otbl.id.toString().substring(otbl.id.length - 1, otbl.id.length);
        entity += "&" + id; ; //当事人分类（1：自然人；2：法人；3：非法人其他组织）
        var ainputs = otbl.getElementsByTagName("input");
        for (var i = 1; i < ainputs.length; i++) {
            var oin = ainputs[i];
            entity +="&"+ oin.value;
        }
        yglist += "~" + entity;
    }

    //被告信息
    var abgtbes = libg.getElementsByTagName("table");
    var bglist = "";
    for (var t = 0; t < abgtbes.length; t++) {
        var otbl = abgtbes[t];

        var entity = "1"; //当事人类型（0：原告；1：被告）
        var id = otbl.id.toString().substring(otbl.id.length - 1, otbl.id.length);
         //当事人分类（1：自然人；2：法人；3：非法人其他组织）
        switch (id) {
            case "5":
                entity += "&1";
                break;
            case "6":
                entity += "&2";
                break;
            case "7":
                entity += "&3";
                break;
        }        
        var ainputs = otbl.getElementsByTagName("input");
        for (var i = 1; i < ainputs.length; i++) {
            var oin = ainputs[i];
            entity += "&" + oin.value;
        }
        bglist += "~" + entity;
    }

    document.getElementById("AppContent").value = yglist + "$" + bglist;

    //设置基本信息
    var pwd = document.getElementById("txtQueryPWD").value; //预立案查询密码
    if (pwd.length == 0) {
        alert("预立案查询密码不能为空！");
        return false;
    }
    var confrimpwd = document.getElementById("txtConfrimQueryPWD").value;
    if (pwd != confrimpwd) {
        alert("查询密码与确认密码不一致！");
        return false;
    }

    var email = document.getElementById("txtEmail").value; //预立案联系人邮箱
    var phone = document.getElementById("txtPhone").value; //预立案联系人电话
    if (phone.length == 0) {
        alert("预立案联系人电话不能为空！");
        return false;
    }
    var casetype = document.getElementById("hdnPreCaseType").value; //预立案类型（1：民事案件；2：商事案件；3：执行案件）
    var startingmark = document.getElementById("StartingMark").value;
    document.getElementById("PreCaseInfo").value = pwd + "~" + email + "~" + phone + "~" + casetype + "~" + startingmark;

    //设置案由
    var sltFirst = document.getElementById("sltFirstList");
    var sltSecond = document.getElementById("sltSecondList");
    var sltThird = document.getElementById("sltThirdList");
    var sltFourth = document.getElementById("sltFourthList");
    var shdnCauseOfActionID = "";
    if (sltFourth.options.length > 1) {
        shdnCauseOfActionID = getselectValue(sltFourth); //sltFourth.value;
    } else {
        if (sltThird.options.length > 1) {
            shdnCauseOfActionID = getselectValue(sltThird);//.value;
        } else {
            if (sltSecond.options.length > 1) {
                shdnCauseOfActionID = getselectValue(sltSecond); //sltSecond.value;
            } else {
                shdnCauseOfActionID = getselectValue(sltFirst); // sltFirst.value;
            }
        }
    }

    if (shdnCauseOfActionID.length == 0) {
        alert("请选择案由分类！");
        return false;
    }

    document.getElementById("hdnCauseOfActionID").value = shdnCauseOfActionID;
    document.getElementById("PreCaseFile").value = document.getElementsByName("uploadfile")[0].value;

    return true;

}


//案由一级下拉框切换
function onFirstSltChange(el) {
    var entity = {}
    entity.pId = "";
    entity.isId = false;
    var ID = getselectValue(el);
    
    var sltSecond = document.getElementById("sltSecondList");
    var sltThird = document.getElementById("sltThirdList");
    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltSecond);
    DelSltOption(sltThird);
    DelSltOption(sltFourth);

    //填充二级下拉框
    entity = AddSelectOption(sltSecond, aSecondList, ID);
    if (!entity.isId) {
        return;
    }

    //填充三级下拉框
    entity = AddSelectOption(sltThird, aThirdList, entity.pId);

    if (!entity.isId) {
        return;
    }
    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, entity.pId);
}
//案由二级下拉框切换
function onSecondSltChange(el) {
    var entity = {}
    entity.pId = "";
    entity.isId = false;

    var ID = getselectValue(el);

    var sltThird = document.getElementById("sltThirdList");
    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltThird);
    DelSltOption(sltFourth);


    //填充三级下拉框
    entity = AddSelectOption(sltThird, aThirdList, ID);

    if (!entity.isId) {
        return;
    }

    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, entity.pId);
}

//案由三级下拉框切换
function onThirdSltChange(el) {

    var entity = {}
    entity.pId = "";
    entity.isId = false;

    var ID = getselectValue(el);

    var sltFourth = document.getElementById("sltFourthList");

    DelSltOption(sltFourth);

    //填充四级下拉框
    entity = AddSelectOption(sltFourth, aFourthList, ID);
}

//下拉框新增类
function AddSelectOption(slt, alist,parentId) {
    var entity = {}
    entity.pId = "";
    entity.isId = false;
    
    for (var s = 0; s < alist.length; s++) {
        if (alist[s].ParentID == parentId) {
            if (!entity.isId) {
                entity.pId = alist[s].CauseOfActionID
                entity.isId = true;
            }
           
            var eItem = new Option(alist[s].CauseOfAction, alist[s].CauseOfActionID);
            slt.options.add(eItem);
        }
    }

    if (!entity.isId) {
        slt.parentNode.className = "g_dn";
    } else {
        slt.parentNode.className = "";
    }

    return entity;
}

//删除下拉框的元素
function DelSltOption(el) {
    for (var i = 0; i < el.options.length; ) {
        el.removeChild(el.options[i]);
    }

    //el.options.add(new Option("", ""));
}

//添加附件
function addzj() {
    var tmpul = document.getElementById("tepzj");
    var ul = document.getElementById("ulzj");
    var chlds = ul.childNodes.length;
    if (chlds > 1) { return; }
    var newul = tmpul.cloneNode(true);
    newul.className = "";

    ul.appendChild(newul);

}